{% extends 'myadmin/base.html' %}

{% block cc %}
<title>Book-Shop图书分类添加</title>
{% endblock %}

{% block con %}
<div class="row-content am-cf">
    <div class="row  am-cf">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">图书分类添加表单</div>
                    <div class="widget-function am-fr">
                        <a href="javascript:;" class="am-icon-cog"></a>
                    </div>
                </div>
                <div class="widget-body am-fr">

                    <form class="am-form tpl-form-line-form" action="{% url 'myadmin_books_insert' %}" method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *所属分类(多选)
                            </label>
                            <div class="am-u-sm-9">
                                <select data-am-selected="{searchBox: 1}" multiple="multiple" name="typeid" style="display: none;">
                                    {% for i in types %}
                                        <option value="{{ i.id }}" {% if i.pid == 0 %} disabled {% endif %}>{{ i.sb }}{{ i.name }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *书名
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="title" required class="tpl-form-input" >
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *作者
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="author" required class="tpl-form-input">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *出版社
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="publisher" class="tpl-form-input">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *出版时间
                            </label>
                            <div class="am-u-sm-9">
                                <input type="date" name="pub_date" required class="tpl-form-input">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *ISBN书号
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="ISBN" required class="tpl-form-input">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *单价
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="price" class="tpl-form-input">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *库存数量
                            </label>
                            <div class="am-u-sm-9">
                                <input type="number" name="num" required class="tpl-form-input">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *推荐语
                            </label>
                            <div class="am-u-sm-9">
                                <textarea name="tuijian" required cols="30" rows="3"></textarea>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                *图书详情
                            </label>
                            <div class="am-u-sm-9">
                                <textarea name="context" id="" cols="30" rows="10" ></textarea>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                图书封面
                            </label>
                            <div class="am-u-sm-9">
                                <div class="am-form-group am-form-file">
                                    <div class="tpl-form-file-img">
                                        <img class="topimg" src="" alt=""style="width: 100px;">
                                    </div>
                                    <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                        <i class="am-icon-cloud-upload"></i>
                                         添加封面
                                    </button>
                                    <input id="doc-form-file" name="img_url" type="file" multiple="">
                                </div>

                            </div>
                        </div>

                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3">
                                <button class="am-btn am-btn-primary tpl-btn-bg-color-success ">
                                    提交
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $('input[name=img_url]').change(function () {
        var file=this.files[0];
        var reader=new FileReader();
        reader.readAsDataURL(file);
        reader.onload=function (e) {
            $('.topimg').attr('src',this.result)
        }
    })
</script>
{% endblock %}


